{% from 'IcsocUIBundle:Macro:actions.html.twig' import button %}
{% import 'IcsocIvrBundle:Ivr:node_fields.html.twig' as ivr %}

<form class="form-horizontal" action="" method="post" name="form">
    {{ ivr.node_name()  }}
    <div class="form-group">
        <label for="form_conditions_name" class="col-sm-3 control-label no-padding-right">{{ 'Conditions Name'|trans }} <font color="red">*</font> </label>
        <div class="col-sm-9" id="form_conditions_name_div">
            <div id="form_conditions_0" style="margin-bottom: 1px">
                <input id="form_conditions_name_0" class="input-sm" type="text" name="form[conditions_name]" style="width: 350px">
                <button id="form_conditions_add" class="btn btn-info btn-xs add" type="button" title="">
                    <i class="ace-icon fa fa-plus"></i>
                </button>
            </div>
        </div>
    </div>
    {{ ivr.ivr_count() }}
    <div class="clearfix well well-sm">
        <div class="col-md-offset-4 col-md-8">
            {{ button('Save', 'btn-node-attr') }}
        </div>
    </div>
</form>
<script language="JavaScript" type="application/javascript">
    var conditionsIndex = 1;
    $('#form_conditions_add').on('click', function() {

        if ($("#form_conditions_name_div").children().length >= 15) {
            gritterAlert("{{ 'Alert'|trans }}", "{{ 'add judge conditions alert info'|trans }}", 'info');
            return false;
        }

        var $content = $('<div id="form_conditions_'+conditionsIndex+'" style="margin-bottom: 1px">\
                            <input id="form_conditions_name_'+conditionsIndex+'" class="input-sm" type="text" name="form[conditions_name]" style="width: 350px">\
                            <button id="form_minus_'+conditionsIndex+'" class="btn btn-info btn-xs minus" type="button" title="">\
                                    <i class="ace-icon fa fa-minus"></i>\
                            </button>\
                        </div>');
         $content.appendTo($('#form_conditions_name_div'));

        /**
         * 删除
         */
        $("#form_minus_"+conditionsIndex).on('click', function() {
            $(this).parent().remove();
        });

        conditionsIndex++;
    });

    function handleConditionsView(treeNodeChild)
    {
        if (treeNodeChild.conditions) {
            $.each(treeNodeChild.conditions,function(index,childNode){
                var $content = $('<div id="form_conditions_'+index+'" style="margin-bottom: 1px">\
                            <input id="form_conditions_name_'+index+'" value="'+childNode+'" class="input-sm" type="text" name="form[conditions_name]" style="width: 350px">\
                                <button id="form_minus_'+index+'" class="btn btn-info btn-xs minus" type="button" title="">\
                                    <i class="ace-icon fa fa-minus"></i>\
                                </button>\
                            </div>');
                if (index != 0 ) {
                    $content.appendTo($('#form_conditions_name_div'));

                    $("#form_minus_"+index).on('click', function() {
                        $(this).parent().remove();
                    });
                } else {
                    $("#form_conditions_name_0").val(childNode);
                }
                conditionsIndex++;

                //$("#btn-node-attr").attr('disabled',true);
            });
        }
    }
</script>